<template>
  <div id="app">
    <!-- <img
      id="musicicon"
      :class="['musicicon', isOff ? '' : 'rotateimg']"
      src="./assets/img/musicbtn.png"
      @click="changeOn"
    /> -->
    <router-view />
    <!-- <audio
      id="audio"
      :src="require('./assets/media/bg.mp3')"
      preload
      controls
      loop
      hidden
    ></audio> -->
  </div>
</template>

<script>
// 阻止页面的滑动默认事件
// document.body.addEventListener(
//   'touchmove',
//   function (e) {
//     e.preventDefault() // 阻止默认的处理方式(阻止下拉滑动的效果)
//   },
//   { passive: false }
// ) // passive 参数不能省略，用来兼容ios和android
import wx from "weixin-js-sdk";
export default {
  name: "App",
  data() {
    return {
      isOff: true,
      height: window.innerHeight, //页面高度
    };
  },
  created() {
    //刷新回到首页
    if (this.$route.path !== "/") {
      this.$router.replace("/");
    }
    //分享
    this.wxShare();
  },
  mounted() {
    // 自动播放音乐效果，解决微信自动播放问题
    // document.addEventListener("touchstart", this.audioAutoPlay, false);
    // document.addEventListener("WeixinJSBridgeReady", this.audioAutoPlay, false);
    // let oAudio = document.querySelector("#audio");
    // oAudio.onended = function () {
    //   //播放完毕，重新循环播放
    //   oAudio.load();
    //   oAudio.play();
    // };

    //防止安卓手机软键盘弹起式撑起页面
    const originalHeight =
      document.documentElement.clientHeight || document.body.clientHeight;
    window.onresize = () => {
      return (() => {
        //键盘弹起与隐藏都会引起窗口的高度发生变化
        const resizeHeight =
          document.documentElement.clientHeight || document.body.clientHeight;
        if (resizeHeight - 0 < originalHeight - 0) {
          //当软键盘弹起，在此处操作
          // console.log("进入到软键盘弹起=========");
          document
            .querySelector("body")
            .setAttribute("style", "height:" + originalHeight + "px;");
          this.scrollerHeight = resizeHeight;
        } else {
          //当软键盘收起，在此处操作
          // console.log("进入到软键盘收起=========");
          document.querySelector("body").setAttribute("style", "height:100%;");
          this.scrollerHeight = "100%";
        }
      })();
    };
  },
  methods: {
    changeOn() {
      let oAudio = document.querySelector("#audio");
      if (this.isOff) {
        oAudio.play(); //让音频文件开始播放
      } else {
        oAudio.pause(); //让音频文件暂停播放
      }
      this.isOff = !this.isOff;
    },
    audioAutoPlay() {
      let audio = document.getElementById("audio");
      this.isOff = false;
      audio.play();
      document.removeEventListener("touchstart", this.audioAutoPlay);
    },
    //分享
    wxShare() {
      var url = encodeURIComponent(window.location.href.split("#")[0]);
      this.$http
        .post("https://www.mahelei.com/index.php/Gm/Wechat/share", { url })
        .then((res) => {
          let data = res.data;
          wx.config({
            debug: false,
            appId: data.appId,
            timestamp: data.timestamp,
            nonceStr: data.nonceStr,
            signature: data.signature,
            jsApiList: [
              "onMenuShareTimeline",
              "onMenuShareAppMessage",
              "onMenuShareQQ",
              "onMenuShareWeibo",
              "onMenuShareQZone",
            ],
          });
        });
      wx.ready(() => {
        var shareData = {
          title: "码赫镭年度下线H5汇总",
          desc: "持续更新",
          link: "https://h5.mahelei.com/OffLineTotal/index.html",
          imgUrl:
            "https://mahelei.oss-cn-beijing.aliyuncs.com/mh/FFL/share.jpg",
          success: () => {},
        };
        wx.onMenuShareTimeline(shareData);
        wx.onMenuShareAppMessage(shareData);
        wx.onMenuShareQQ(shareData);
        wx.onMenuShareWeibo(shareData);
        wx.onMenuShareQZone(shareData);
      });
    },
  },
};
</script>

<style>
html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  max-width: 750px;
  margin: 0 auto;
}
p {
  margin: 0;
}
#app {
  position: relative;
  width: 100%;
  height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  font-family: -apple-system, BlinkMacSystemFont, Arial, Roboto, "PingFang SC",
    "simhei";
  background-color: #fff;
  color: #000;
  font-size: 14px;
}
.back {
  position: fixed;
  top: 3rem;
  left: 3rem;
  width: 3%;
  z-index: 9;
}
.musicicon {
  position: absolute;
  top: 1.5rem;
  right: 2rem;
  width: 55px;
  height: 55px;
  z-index: 4;
}
.rotateimg {
  animation: rotateimgani 3s linear infinite;
}
@keyframes rotateimgani {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
.box {
  position: relative;
  width: 100%;
  height: 100%;
}
.clmcenter {
  display: flex;
  flex-flow: column nowrap;
  justify-content: center;
  align-items: center;
}
.clmstart {
  display: flex;
  flex-flow: column nowrap;
  justify-content: flex-start;
  align-items: center;
}
.bg {
  background: url("./assets/img/bg.jpg") no-repeat bottom center;
  background-size: cover;
}
.apcbg {
  background-color: rgba(0, 0, 0, 0.7);
}
.infobtn {
  position: relative;
  font-size: 2rem;
  border: none;
  padding: 1.5rem 2.5rem;
  border-radius: 0.5rem;
  letter-spacing: 1px;
  color: #ffffff;
  margin-bottom: 3rem;
  text-align: center;
  /* text-transform: uppercase; */
  transition: 0.5s;
  background-size: 200% auto;
  box-shadow: 0 3px 3px 1px #efefeff2;
  background-image: linear-gradient(
    to right,
    #152236 0%,
    #313423b8 51%,
    #152236 100%
  );
}
.infobtn:hover {
  background-position: right center;
}
.btn {
  font-size: 2rem;
  padding: 1.2rem 3rem;
  border-radius: 8px;
  margin-top: 3rem;
}
.btnani {
  animation: btnanito 2s linear infinite;
}
@keyframes btnanito {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}
/*select和input设置相同大小*/
select,
input {
  appearance: none;
  -moz-appearance: none;
  -webkit-appearance: none;
  border-style: none;
  padding: 0;
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
}
select:focus,
input:focus {
  outline: 0;
}
select {
  background: #ffffff url(./assets/img/icon.png) no-repeat right center;
  background-size: 5% auto !important;
  background-position: right 3% top 1rem;
  text-align: center;
  text-align-last: center;
}
select::-ms-expand {
  display: none;
}
/*去除a标签点击时出现闪现黑背景  ——手机端*/
a,
a:hover,
a:active,
a:visited,
a:link,
a:focus,
img {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  -webkit-tap-highlight-color: transparent;
  outline: none;
  background: none;
  text-decoration: none;
}
/* vant样式修改 */
.van-toast {
  width: auto !important;
  font-size: 1.8rem !important;
  padding: 20px !important;
}
.van-toast__text {
  padding: 1rem;
  line-height: 30px;
}
.van-loading__spinner {
  width: 40px !important;
  height: 40px !important;
}
</style>
